package jdl.tokenization;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import jdl.tokenization.states.IState;
import jdl.tokenization.states.InitialState;

public class TokenParser {
	private Hashtable<Character, TokenType> hashtable = new Hashtable<Character, TokenType>();

	public TokenParser() {
		hashtable.put('(', TokenType.LEFT_BRACKET);
		hashtable.put(')', TokenType.RIGHT_BRACKET);
		hashtable.put('0', TokenType.NUMBER);
		hashtable.put('1', TokenType.NUMBER);
		hashtable.put('2', TokenType.NUMBER);
		hashtable.put('3', TokenType.NUMBER);
		hashtable.put('4', TokenType.NUMBER);
		hashtable.put('5', TokenType.NUMBER);
		hashtable.put('6', TokenType.NUMBER);
		hashtable.put('7', TokenType.NUMBER);
		hashtable.put('8', TokenType.NUMBER);
		hashtable.put('9', TokenType.NUMBER);
	}

	public List<Token> getTokens(String string) {
		List<Token> tokens = new ArrayList<Token>();
		IState state = new InitialState(tokens, hashtable);
		for (char symbol : string.toCharArray()) {
			state.analyzeSymbol(symbol);
			state = state.getNextState();
		}
		state.endOfSymbols();
		return tokens;
	}
}
